#ifndef FUNCTIONS_H_
#define FUNCTIONS_H_

#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <cmath>
#include <bitset>
#include <stdlib.h>
#include <stdint.h>
#include "Constantes.h"

using std::vector;
using std::string;
using std::stringstream;
using std::bitset;

struct t_termino {
	string word;
	unsigned int frecuency;
	vector <unsigned int> pos;   //se puede mejorar N1
	unsigned int document;
} typedef Termino;

struct t_data {
	unsigned int document;
	unsigned int frecuency;
	vector <unsigned int>* pos;
} typedef Data;

typedef struct {//t_termYFrec
	string termino;
	unsigned short int vecesFueConsultado;
	vector<Data>* datosTermino;
} TermYFrecQuery;

struct t_register {
	unsigned int docsNumber;
	string word;
	vector <Data>* v_data;
} typedef Register;

struct t_query_token {
	string word;
	unsigned int pos;
	vector<Data> * v_data;
} typedef QueryToken;

struct t_cache_token {
	string word;
	unsigned int pos;
	vector<Data> * v_data;
} typedef CacheToken;

struct t_match {
	unsigned int document;
	unsigned int long_match;
	bool fraseCompleta;
}typedef Match;

namespace convertTypes {

string intToString (int num);
int hexToInt (char value);
string toLower (string upper);
int strToint (std::string str);

/**
 * el string debe ser ser un caracter por cada bit
 */
bitset<8> strToBitset(std::string str);
int8_t bitSetToInt(bitset<8>);
uint8_t stringToInt8(string);


bitset<32> hexaToBitset(string);

/**
 * Debe recibir un char [4] representado en hexadecimal
 */
unsigned int hexaToUInt(char*);

/**
 * Transforma un int en un string de hexa de 4 bytes.
 * cada byte contiene 2 caracteres hexa. ej: 00 6F E8 A1 (0000 0000  0110 1111  1110 1000  1010 0001)
 */
string hexaToString(unsigned int);
bitset<32> strToBitset32(std::string str);
string hexaToBits(std::string cadenaHexa);
string getHexCharacter(char c);
unsigned int charToInt(char[]);

void printQueryToken(QueryToken*);
void printQueryTokens(vector<QueryToken>*);

void printTimeToFindNResults(clock_t initialTime, unsigned int N);
void printNoResultsFound();

void cleanVectorData(vector<Data>*);
void cleanVectorRegister(vector<Register>*);
void cleanVectorQueryToken(vector<QueryToken>*);
void cleanQueryToken(QueryToken);

string appendSlash(string);
string removeSlash(string);
int binarySearch(int, vector<unsigned int>*);

int cmp_match(const void*, const void*);
}
#endif /* FUNCTIONS_H_ */
